package adminorg;

import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.themes.Runo;
import java.io.Serializable;


public class confWindow extends Window implements Button.ClickListener,Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -8783435695230326733L;
	Callback callback;
	Button close = new Button("Отмена",this);
	Button submit = new Button("ОК",this);
	
	public confWindow(String caption, String question, Callback callback){
		super(caption);
		setModal(true);
		this.callback = callback;
		VerticalLayout l = (VerticalLayout) this.getContent();
		l.setSizeUndefined();
		this.setStyleName(Runo.WINDOW_DIALOG);
    	HorizontalLayout h = new HorizontalLayout();
    	Label message = new Label(question);
      	h.addComponent(submit);
    	h.addComponent(close);
    	l.addComponent(message);
    	l.addComponent(h);
	}

	@Override
	public void buttonClick(ClickEvent event) {
		if (getParent() != null) {
            ((Window) getParent()).removeWindow(this);
        }
        callback.onDialogResult(event.getSource() == submit);
		
	}
	
	 public interface Callback extends Serializable {

	        public void onDialogResult(boolean resultIsYes);
	    }
	
	

}
